import { defineStore } from 'pinia'
import { GetCollectionTimeApi } from '@/apis/collection'
import { changeTakeStatusApi } from '@/apis/user'

export const useAppStore = defineStore('app', {
  state: () => ({
    endTime: 0,
    endTim: 0,
    takeOrders: '0'
  }),
  getters: {
    getTakeInfo(state) {
      return state
    }
  },
  actions: {
    async getCollectionTime() {
      const res = await GetCollectionTimeApi()
      this.endTim = res.endTim
      this.endTime = res.endTime
      this.takeOrders = res.takeOrders
      return res
    },
    async changeTakeStatus() {
      if (this.takeOrders == '0') {
        this.takeOrders = '1'
      } else {
        this.takeOrders = '0'
      }
      const res = await changeTakeStatusApi({ status: this.takeOrders })
      console.log(res)
    }
  }
})
